<script>
$(document).ready(function() {
	<?php
	if ($updated == 1) echo 'showNoti("Khách hàng: '.$name.'", "Thêm khách hàng mới thành công!", "Ok");';
	if ($failed == 2) echo 'showNoti("Nhóm khách hàng: '.$name.'", "Cập nhập nhóm khách hàng thất bại!", "Err");';
	if ($updated == 2) echo 'showNoti("Nhóm khách hàng: '.$name.'", "Cập nhập nhóm khách hàng thành công!", "Ok");';
	if ($added == 2) echo 'showNoti("Nhóm khách hàng: '.$name.'", "Thêm nhóm khách hàng thành công!", "Ok");';
	?>
	$('.circle_plus').parent().bind('click', function() {
		if ($('.tab-content').length) {
			if ($('#tabs-0').is(':hidden')) {
		        $('#myModal').modal('show');
				return false;
			}
		}
	});
});
</script>
<?php
echo module_open();
if ($GLOBALS['user']['level'] == 1)
{
?>
<tr class="no-border">
    <td>
    	<input type="hidden" class="tabId" value="<?php echo $GLOBALS['var']['mytab'] ?>" />
        <ul id="myTab" class="nav nav-tabs">
            <li class="hide640<?php echo ($GLOBALS['var']['mytab'] == 0 ? ' active' : '') ?>" onclick="set_mytab($(this)); $('#moduleInfo').attr('data-table', 'customers')"><a href="#tabs-0" data-toggle="tab">Danh sách khách hàng</a></li>
            <li class="hide640<?php echo ($GLOBALS['var']['mytab'] == 1 ? ' active' : '') ?>" onclick="set_mytab($(this)); $('#moduleInfo').attr('data-table', 'usergroups')"><a href="#tabs-1" data-toggle="tab">Nhóm khách hàng</a></li>
            <li class="dropdown active show640">
                <a class="dropdown-toggle" data-toggle="dropdown" href="#"><span class="current-tab-name">Danh sách khách hàng</span> <span class="caret"></span></a>
                <ul class="dropdown-menu">
                	<li <?php echo ($GLOBALS['var']['mytab'] == 0 ? ' active' : '') ?>onclick="set_mytab($(this)); $('#moduleInfo').attr('data-table', 'customers')"><a href="#tabs-0" data-toggle="tab">Danh sách khách hàng</a></li>
            		<li <?php echo ($GLOBALS['var']['mytab'] == 1 ? ' active' : '') ?>onclick="set_mytab($(this)); $('#moduleInfo').attr('data-table', 'usergroups')"><a href="#tabs-1" data-toggle="tab">Nhóm khách hàng</a></li>
                </ul>
            </li>
        </ul>
        <div id="myTabContent" class="tab-content">
	        <div id="tabs-0" class="tab-pane<?php echo ($GLOBALS['var']['mytab'] == 0 ? ' active' : '') ?>">
	            <table cellpadding="0" cellspacing="0" width="100%" border="0">
<?php
}
					if ($page_list)
					{
					?>
					<tr class="show980">
						<td class="fr page" colspan="10">
							<?php echo $page_list ?>
						</td>
					</tr>
					<?php
					}
					?>
					<tr>
						<?php if ($GLOBALS['per']['del']) echo '<td class="head center" width="3%"><input type="checkbox" class="checkAll" /></td>'; ?>
						<td class="head center" width="2%">#</td>
						<td class="head">Mã khách hàng</td>
						<td class="head">Họ tên</td>
						<td class="head hide640 right">Chiết khấu</td>
						<td class="head hide640">Điện thoại</td>
						<td class="head hide640">Ngày tạo</td>
						<td class="head center" width="1%">&nbsp;</td>
					</tr>
					<?php
					if (is_array($customers) && count($customers))
					{
						$i = 1;
						foreach ($customers as $row)
						{
					?>
					<tr class="highlight<?php echo ($row['isnew'] ? ' table-flag-red' : '') ?>" id="<?php echo $row['id'] ?>" name="<?php echo $row['fullname'] ?>">
						<?php if ($GLOBALS['per']['del']) echo '<td class="fr center">'.sel_item($row['id'], $row['id'] == 1).'</td>'; ?>
						<td class="fr center" width="1%"><?php echo stt($row['id'], $rowstart + $i++) ?></td>
						<td class="fr"><?php echo $row['code'] ?></td>
						<td class="fr"><?php echo $row['fullname'] ?></td>
						<td class="fr hide640 right"><?php echo $row['chietkhau'] ?>%</td>
						<td class="fr hide640"><?php echo $row['phone'] ?></td>
						<td class="fr hide640"><?php echo strftime(TIME_STR, strtotime($row['date_added'])) ?></td>
						<td class="fr center" nowrap="nowrap">
							<?php
							if ($GLOBALS['per']['edit']) echo '<a title="Cập nhập" href="'.$url_str.'/update/'.$row['id'].$uri_str.'"><div class="icon glyphicons edit"></div></a>';
							if ($GLOBALS['per']['del'])
					        {
					        	if ($row['id'] != 1)
					        	{
					        		echo del_restore_link($row['id'], $row['deleted']);
					        	}
					        	else
					        	{
					        		echo '<div class="icon glyphicons rotation_lock" title="Đã khóa chức năng xóa" style="margin-left: 3px; margin-right: 3px;"></div>';
					        	}
					        }
							?>
						</td>
					</tr>
					<?php
						}
					}
					else
					{
						echo no_data_mes(7);
					}
					if ($GLOBALS['user']['level'] == 1)
					{
					?>
				</table>
			</div>
			<div id="tabs-1" class="tab-pane<?php echo ($GLOBALS['var']['mytab'] == 1 ? ' active' : '') ?>">
	            <table cellpadding="0" cellspacing="0" width="100%" border="0">
	            	<tr class="nodrop">
					    <?php if ($GLOBALS['per']['del']) echo '<td class="head center" width="3%"><input type="checkbox" class="checkAll" /></td>'; ?>
					    <td class="head center" width="2%">#</td>
					    <td class="head" width="50%">Tên nhóm</td>
					    <td class="head hide480" width="10%">Chiết khấu (%)</td>
					    <td class="head hide480" width="15%">Ngày tạo</td>
					    <td class="head center" width="10%">Kích hoạt</td>
					    <td class="head" width="1%">&nbsp;</td>
					</tr>
					<?php
					if (count($usergroups) && is_array($usergroups))
					{
					    $i = 1;
					    foreach ($usergroups as $row)
					    {
					?>
					<tr class="highlight<?php echo ($row['isnew'] ? ' table-flag-red' : '') ?>" id="<?php echo $row['id'] ?>" name="<?php echo $row['name_vn'] ?>">
						<?php if ($GLOBALS['per']['del']) echo '<td class="fr center">'.sel_item($row['id'], $row['id'] == 1 || $row['id'] == 2).'</td>'; ?>
						<td class="fr center"><?php echo stt($row['id'], $i++) ?></td>
						<td class="fr">
							<?php echo $row['name_vn'] ?>
							<?php echo ($row['khachhang'] ? '<div class="note">Khách hàng: '.number_format($row['khachhang']).'</div>' : '') ?>
						</td>
						<td class="fr hide480"><?php echo $row['chietkhau'] ?></td>
					    <td class="fr hide480"><?php echo strftime(TIME_STR, strtotime($row['date_added'])) ?></td>
						<td class="fr center"><?php echo change_status($row['id'], $row['active'], 'active', '', '', '', !$GLOBALS['per']['edit']) ?></td>
						<td class="fr center" nowrap="nowrap">
					        <?php if ($GLOBALS['per']['edit']) echo edit_alink($row['id'], '', 'updateLink'); ?>
					        <?php
					        if ($GLOBALS['per']['del'])
					        {
					        	if ($row['id'] != 1 && $row['id'] != 2)
					        	{
					        		echo del_restore_link($row['id'], $row['deleted'], false, false, 'usergroups');
					        	}
					        	else
					        	{
					        		echo '<div class="icon glyphicons rotation_lock" title="Đã khóa chức năng xóa" style="margin-left: 3px; margin-right: 3px;"></div>';
					        	}
					        }
					        ?>
					    </td>
					</tr>
					<?php
					    	if ($GLOBALS['per']['add'] || $GLOBALS['per']['edit'])
					        {
					            echo '<input class="textData '.$row['id'].'" data-field="name_vn" value="'.$row['name_vn'].'" />';
					            echo '<input class="textData '.$row['id'].'" data-field="chietkhau" value="'.$row['chietkhau'].'" />';
					        }
					    }
					}
					?>
	            </table>
	        </div>
	    </div>
	</td>
</tr>
<?php
}
echo module_close();
if ($GLOBALS['per']['add'] || $GLOBALS['per']['edit'])
{
?>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog">
		<?php
        echo form_open($action, array('id' => 'updateFrm'));
        echo form_input(array('type' => 'hidden', 'name' => 'token', 'value' => $GLOBALS['var']['token']));
        ?>
		<div class="modal-content">
			<div class="modal-body">
		    	<table cellpadding="0" cellspacing="0" width="100%" border="0" style="margin:0px;">
		        	<tr>
		            	<td style="padding: 5px 0px">Nhóm <span style="color:red">*</span></td>
		                <td style="position: relative; padding: 5px 0px">
		                    <input type="text" data-required="1" class="medium" name="name_vn" id="name_vn" style="width:140px;" />
		                    <div class="errordiv name_vn"><div class="arrow"></div>Vui lòng nhập tên nhóm!</div>
		                </td>
		            </tr>
					<tr>
		            	<td style="padding: 5px 0px">Chiết khấu (%)<span style="color:red">*</span></td>
		                <td style="position: relative; padding: 5px 0px">
		                    <input type="text" data-required="1" class="medium" name="chietkhau" id="chietkhau" style="width:30px;" />
		                    <div class="errordiv chietkhau"><div class="arrow"></div>Vui lòng chọn % chiết khấu!</div>
		                </td>
		            </tr>
		        </table>
			</div>
			<div class="modal-footer">
				<?php echo form_input(array('type' => 'hidden', 'name' => 'id', 'class' => 'id')); ?>
                <div id="submitBtn" class="btn btn-success"><i class="icon glyphicons white ok_2"></i><span>Cập nhập</span></div>
                <div class="btn btn-danger" data-dismiss="modal"><i class="icon glyphicons white remove_2"></i><span>Hủy bỏ</span></div>
			</div>
		</div>
		<?php echo form_close(); ?>
	</div>
</div>
<?php
}
?>